<template>
  <div :style="{ ...coreStyle.marginSame(8) }">
    <a-card>
      <a-form ref="taskParamFormQueryRef" :model="taskParamFormQueryModel" labelAlign="left" layout="vertical" :style="{ ...coreStyle.marginBottom(10) }">
        <a-row :gutter="16" v-show="!taskParamFormQueryVisible">
          <a-col :span="8">
            <a-form-item :style="{ ...coreStyle.marginBottom(-8) }">
              <a-input-search v-model:value="taskParamFormQueryModel.keySearchVo" placeholder="关键字搜索" :disabled="taskParamFormQuerySubmitting" @search="taskParamFormQuerySearch" />
            </a-form-item>
          </a-col>
          <a-col :span="16">
            <a-button type="link" :style="{ ...coreStyle.floatRight }" @click="taskParamFormQueryUpDown">
              展开
              <CoreIcon :icon="coreStyle.antBtnIconExpand" :size="14" />
            </a-button>
          </a-col>
        </a-row>
        <a-row :gutter="16" v-show="taskParamFormQueryVisible">
          <a-col :span="8">
            <a-form-item>
              <a-input-search v-model:value="taskParamFormQueryModel.keySearchVo" placeholder="关键字搜索" :disabled="taskParamFormQuerySubmitting" @search="taskParamFormQuerySearch" />
            </a-form-item>
          </a-col>
          <a-col :span="16">
          </a-col>
          <a-col :span="8">
            <a-form-item label="参数名">
              <a-input v-model:value="taskParamFormQueryModel.paramNameAndLike" placeholder="输入参数名" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="参数值">
              <a-input v-model:value="taskParamFormQueryModel.paramValueAndLike" placeholder="输入参数值" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="排序权重">
              <a-input-number v-model:value="taskParamFormQueryModel.weightOrder" :style="{ ...coreStyle.width('100%') }" />
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item label="外键Id">
              <a-input v-model:value="taskParamFormQueryModel.fkidAndLike" placeholder="输入外键Id" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-space :style="{ ...coreStyle.floatRight }">
              <a-button type="dashed" :style="{ ...coreStyle.antBtnReset }" @click="taskParamFormQueryReset">
                <CoreIcon :icon="coreStyle.antBtnIconReset" :size="14" />
                重置
              </a-button>
              <a-button :loading="taskParamFormQuerySubmitting" type="dashed" :style="{ ...coreStyle.antBtnQuery }" @click="taskParamFormQuerySearch">
                <CoreIcon :icon="coreStyle.antBtnIconQuery" :size="14" />
                查询
              </a-button>
              <a-button type="dashed" ghost :style="{ ...coreStyle.antBtnRetract }" @click="taskParamFormQueryUpDown">
                收起
                <CoreIcon :icon="coreStyle.antBtnIconRetract" :size="14" />
              </a-button>
            </a-space>
          </a-col>
        </a-row>
      </a-form>
      <a-space>
        <a-button type="dashed" :style="{ ...coreStyle.antBtnAdd }" @click="taskParamAdd">
          <CoreIcon :icon="coreStyle.antBtnIconAdd" :size="14" />
          新增
        </a-button>
        <a-button v-if="taskParamListSelectLength === 1" type="dashed" :style="{ ...coreStyle.antBtnUpdate }" @click="taskParamUpdate">
          <CoreIcon :icon="coreStyle.antBtnIconUpdate" :size="14" />
          修改
        </a-button>
        <a-popconfirm v-if="taskParamListSelectLength > 0" title="确认删除？" okType="dashed" placement="bottom" @confirm="taskParamDelete">
          <a-button type="dashed" :style="{ ...coreStyle.antBtnDelete }">
            <CoreIcon :icon="coreStyle.antBtnIconDelete" :size="14" />
            删除
          </a-button>
        </a-popconfirm>
        <a-button v-if="taskParamListSelectLength === 1" type="dashed" :style="{ ...coreStyle.antBtnDetail }" @click="taskParamDetailInfo">
          <CoreIcon :icon="coreStyle.antBtnIconDetail" :size="14" />
          详情
        </a-button>
      </a-space>
      <a-space :style="{ ...coreStyle.floatRight }">
        <a-button type="dashed" :style="{ ...coreStyle.antBtnTemplateDownload }" @click="taskParamTemplateDownload">
          <CoreIcon :icon="coreStyle.antBtnIconTemplateDownload" :size="14" />
          模版下载
        </a-button>
        <a-button type="dashed" :style="{ ...coreStyle.antBtnImport }" @click="taskParamDataImport">
          <CoreIcon :icon="coreStyle.antBtnIconImport" :size="14" />
          导入
        </a-button>
        <a-button type="dashed" :style="{ ...coreStyle.antBtnExport }" @click="taskParamDataExport">
          <CoreIcon :icon="coreStyle.antBtnIconExport" :size="14" />
          导出
        </a-button>
        <a-button type="dashed" ghost shape="circle" :style="{ ...coreStyle.antBtnRefresh }" @click="taskParamListGetDataSet">
          <CoreIcon :icon="coreStyle.antBtnIconRefresh" :size="22" />
        </a-button>
      </a-space>
      <a-table
        rowKey="id"
        :columns="taskParamListColumns"
        :data-source="taskParamListDataSet"
        :loading="taskParamListLoading"
        :pagination="false"
        bordered
        :customRow="taskParamListCustomRow"
        :row-selection="{ fixed: true, selectedRowKeys: taskParamListSelectedRowKeys, onChange: taskParamListRowOnChange }"
        :scroll="{ x: '100%', y: 550 }"
        :style="{ ...coreStyle.marginTop(10) }"
      >
      </a-table>
      <a-pagination
        v-model:current="taskParamListDataPage"
        v-model:pageSize="taskParamListDataRows"
        :total="taskParamListDataCount"
        show-size-changer
        show-quick-jumper
        :page-size-options="[ ...coreStyle.antdPaginationPageSizeOptions ]"
        :show-total="(total, range) => coreStyle.antdPaginationShowTotal(total, range)"
        :style="{ ...coreStyle.marginTop(10), ...coreStyle.textAlignCenter }"
        @change="taskParamListPaginationChange"
        @showSizeChange="taskParamListPaginationShowSizeChange"
        v-if="taskParamListPaginationVisible"
      >
      </a-pagination>
      <p :style="{ ...coreStyle.marginTop(14), ...coreStyle.marginBottom(6), ...coreStyle.textAlignCenter }" v-if="!taskParamListPaginationVisible">
        {{ coreStyle.antdPaginationShowTotal(taskParamListDataCount) }}
      </p>
    </a-card>
    <a-drawer
      v-model:visible="taskParamEditDrawerVisible"
      title="编辑任务参数信息"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 30, 0) }"
      @close="taskParamEditDrawerOnClose"
    >
      <a-form ref="taskParamFormRef" :model="taskParamFormModel" :rules="taskParamFormRules" labelAlign="left" layout="vertical">
        <a-row :gutter="16">
          <a-col :span="12">
            <a-form-item label="参数名" name="paramName">
              <a-input v-model:value="taskParamFormModel.paramName" placeholder="输入参数名" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="参数值" name="paramValue">
              <a-input v-model:value="taskParamFormModel.paramValue" placeholder="输入参数值" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="排序权重" name="weightOrder">
              <a-input-number v-model:value="taskParamFormModel.weightOrder" :style="{ ...coreStyle.width('100%') }" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="外键Id" name="fkid">
              <a-input v-model:value="taskParamFormModel.fkid" placeholder="输入外键Id" />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnReset }" @click="taskParamFormReset">
            <CoreIcon :icon="coreStyle.antBtnIconReset" :size="14" />
            重置
          </a-button>
          <a-button :loading="taskParamFormSaveSubmitting" type="dashed" :style="{ ...coreStyle.antBtnNextAdd }" @click="taskParamFormNextAdd">
            <CoreIcon :icon="coreStyle.antBtnIconNextAdd" :size="14" />
            继续录入
          </a-button>
          <a-button :loading="taskParamFormSaveSubmitting" type="dashed" :style="{ ...coreStyle.antBtnSave }" @click="taskParamFormSave">
            <CoreIcon :icon="coreStyle.antBtnIconSave" :size="14" />
            保存
          </a-button>
        </a-space>
      </div>
    </a-drawer>
    <a-drawer
      v-model:visible="taskParamDetailDrawerVisible"
      title="任务参数详细信息"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 30, 0) }"
    >
      <a-space direction="vertical" :size="20" :style="{ ...coreStyle.width('100%') }">
        <a-descriptions title="基础信息" :column="2" bordered>
          <a-descriptions-item label="参数名" :span="1">{{ taskParamDetailModel.paramName }}</a-descriptions-item>
          <a-descriptions-item label="参数值" :span="1">{{ taskParamDetailModel.paramValue }}</a-descriptions-item>
          <a-descriptions-item label="排序权重" :span="1">{{ taskParamDetailModel.weightOrder }}</a-descriptions-item>
          <a-descriptions-item label="外键Id" :span="1">{{ taskParamDetailModel.fkid }}</a-descriptions-item>
        </a-descriptions>
      </a-space>
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnUpdate }" @click="taskParamDetailUpdate">
            <CoreIcon :icon="coreStyle.antBtnIconUpdate" :size="14" />
            修改
          </a-button>
        </a-space>
      </div>
    </a-drawer>
    <a-drawer
      v-model:visible="taskParamDataImportDrawerVisible"
      title="任务参数数据导入"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 50, 0) }"
    >
      <a-row :gutter="16">
        <a-col :span="24">
          <FileUpload ref="taskParamDataImportFileUploadRef" :fileModule="taskParamDataImportFileModule" @change="taskParamDataImportFileUploadChange" />
          <a-input v-model:value="taskParamDataImportFileUrl" disabled addonBefore="导入文件url:" placeholder="输入导入文件url">
            <template #addonAfter>
              <a-button type="link" size="small" @click="taskParamDataImportFileUrlSelectFileClick">选择文件</a-button>
            </template>
          </a-input>
        </a-col>
      </a-row>
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button :loading="taskParamDataImportSaveSubmitting" type="dashed" :style="{ ...coreStyle.antBtnImportData }" @click="taskParamToDataImport">
            <CoreIcon :icon="coreStyle.antBtnIconImportData" :size="14" />
            导入数据
          </a-button>
        </a-space>
      </div>
    </a-drawer>
    <a-drawer
      v-model:visible="taskParamDataImportFileSelectDrawerVisible"
      title="文件选择"
      placement="right"
      :closable="false"
      destroyOnClose
      :width="'80%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 0, 0) }"
    >
      <FileSelect :fileModule="taskParamDataImportFileModule" @change="taskParamDataImportFileSelectChange" />
    </a-drawer>
    <a-drawer
      v-model:visible="taskParamDataExportDrawerVisible"
      title="任务参数数据导出"
      placement="right"
      :closable="false"
      :width="'40%'"
      :header-style="{ ...coreStyle.antdDrawerHeader }"
      :body-style="{ ...coreStyle.margin(50, 0, 50, 0) }"
    >
      <DataExportColumnSelect :optionalDataExportFieldList="taskParamOptionalDataExportFieldList" :selectedDataExportFieldList="taskParamSelectedDataExportFieldList" />
      <div :style="{ ...coreStyle.antdDrawerFooter }">
        <a-space>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnQueryDataExport }" @click="taskParamToDataExport(false)">
            <CoreIcon :icon="coreStyle.antBtnIconQueryDataExport" :size="14" />
            查询数据导出
          </a-button>
          <a-button type="dashed" :style="{ ...coreStyle.antBtnAllDataExport }" @click="taskParamToDataExport(true)">
            <CoreIcon :icon="coreStyle.antBtnIconAllDataExport" :size="14" />
            全部数据导出
          </a-button>
        </a-space>
      </div>
    </a-drawer>
  </div>
</template>

<script lang="ts">
import { Options, Vue } from 'vue-class-component'
import { mapStores } from 'pinia'
import { useCoreToolStore } from '/@/store/modules/cn/core/tool/coreToolStore'
import type { Res } from '/@/tool/Res'
import type { Param } from '/@/tool/Param'

import type { DataExportFieldAO } from '/@/model/cn/core/tool/ao/DataExportFieldAO'
import type { DataExportAO } from '/@/model/cn/core/tool/ao/DataExportAO'
import { toDataExportAO } from '/@/model/cn/core/tool/ao/DataExportAO'

import { useTaskParamStore } from '/@/store/modules/cn/core/kpis/taskParamStore'

import type { TaskParam } from '/@/model/cn/core/kpis/eo/TaskParam'
import { toTaskParam } from '/@/model/cn/core/kpis/eo/TaskParam'

import type { TaskParamQO } from '/@/model/cn/core/kpis/qo/TaskParamQO'
import { toTaskParamQO } from '/@/model/cn/core/kpis/qo/TaskParamQO'

import type { TaskParamVO } from '/@/model/cn/core/kpis/vo/TaskParamVO'
import { toTaskParamVO } from '/@/model/cn/core/kpis/vo/TaskParamVO'

@Options({
  name: 'TaskParam',
  components: {
  },
  computed: {
    ...mapStores(useCoreToolStore, useTaskParamStore),
  },
})
export default class TaskParam extends Vue {

  taskParamListDataSet: Array<TaskParamVO> = []

  taskParamListColumns: Array<object> = [
    {
      title: '参数名',
      dataIndex: 'paramName',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
    {
      title: '参数值',
      dataIndex: 'paramValue',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
    {
      title: '排序权重',
      dataIndex: 'weightOrder',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
    {
      title: '外键Id',
      dataIndex: 'fkid',
      align: 'center',
      // ellipsis: true,
      // width: 200,
    },
  ]

  taskParamListLoading: boolean = false

  taskParamListSelectedRowKeys: string[] = []

  taskParamListSelectData: Array<TaskParamVO> = []

  taskParamListSelectLength: number = 0

  taskParamListSelectCurrentRowIndex: number = -1

  taskParamListSelectCurrentRowData: TaskParamVO = toTaskParamVO()

  taskParamListPaginationVisible: boolean = true

  taskParamListDataPage: number = 1

  taskParamListDataRows: number = 10

  taskParamListDataCount: number = 0

  taskParamListRowClickTimeout: number | null = null

  taskParamListRowOnChange(selectedRowKeys, selectedRows) {
    this.taskParamListSelectedRowKeys = [ ...selectedRowKeys ]
    this.taskParamListSelectData = [ ...selectedRows ]
    this.taskParamListSelectLength = selectedRows.length
  }

  taskParamListCustomRow(record, index) {
    return {
      'class': index === this.taskParamListSelectCurrentRowIndex ? 'ant-table-row-selected' : '',
      onClick: (event) => {
        if (this.taskParamListRowClickTimeout) {
          clearTimeout(this.taskParamListRowClickTimeout)
          this.taskParamListRowClickTimeout = null
        } else {
          this.taskParamListRowClickTimeout = setTimeout(() => {
            this.taskParamListRowClickTimeout = null
            this.taskParamListSelectCurrentRowIndex = index
            this.taskParamListSelectCurrentRowData = { ...record }
            let selectedRowKeys = [ ...this.taskParamListSelectedRowKeys ]
            let selectedRows = [ ...this.taskParamListSelectData ]
            if (selectedRowKeys.includes(record.id)) {
              this.taskParamListRowOnChange([ ...selectedRowKeys.filter(eo => { return eo !== record.id }) ], [ ...selectedRows.filter(eo => { return eo.id !== record.id }) ])
            } else {
              selectedRowKeys.push(record.id)
              selectedRows.push(record)
              this.taskParamListRowOnChange([ ...new Set(selectedRowKeys) ], [ ...new Set(selectedRows) ])
            }
          }, 200)
        }
      },
      onDblclick: (event) => {
        this.taskParamStore.pkVo(this.$toParam<TaskParamQO>({ id: record.id } as TaskParamQO)).then((res: Res<TaskParamVO>) => {
          if (res.succ) {
            this.taskParamDetailModel = { ...res.data[0] }
            this.taskParamDetailDrawerVisible = true
          } else {
            this.$message.error(res.msg, 6)
          }
        })
      },
    }
  }

  taskParamListGetDataSet() {
    this.taskParamListLoading = true
    this.taskParamListRowOnChange([], [])
    this.taskParamListSelectCurrentRowIndex = -1
    this.taskParamListSelectCurrentRowData = toTaskParamVO()
    this.taskParamStore.pagingVo(this.$toParam<TaskParamQO>({ weightOrderAsc: 'y' } as TaskParamQO, this.taskParamListDataPage, this.taskParamListDataRows)).then((res: Res<TaskParamVO>) => {
      if (res.succ) {
        this.taskParamListPaginationVisible = true
        this.taskParamListDataSet = [ ...res.data ]
        this.taskParamListDataCount = res.count
        setTimeout(() => { this.taskParamListLoading = false }, 500)
      } else {
        this.$message.error(res.msg, 6)
        setTimeout(() => { this.taskParamListLoading = false }, 500)
      }
    }).catch(err => {
      setTimeout(() => { this.taskParamListLoading = false }, 500)
    })
  }

  taskParamListPaginationChange() {
    this.taskParamListGetDataSet()
  }

  taskParamListPaginationShowSizeChange() {
    this.taskParamListGetDataSet()
  }

  taskParamFormQueryVisible: boolean = false

  taskParamFormQuerySubmitting: boolean = false

  taskParamFormQueryModel: TaskParamQO = toTaskParamQO()

  taskParamFormQueryUpDown() {
    this.taskParamFormQueryVisible = !this.taskParamFormQueryVisible
  }

  taskParamFormQueryReset() {
    if (this.$refs.taskParamFormQueryRef) {
      this.$refs.taskParamFormQueryRef.resetFields()
      this.taskParamFormQueryModel = toTaskParamQO()
    }
  }

  taskParamFormQuerySearch() {
    this.taskParamFormQuerySubmitting = true
    this.taskParamListLoading = true
    this.taskParamListRowOnChange([], [])
    this.taskParamListSelectCurrentRowIndex = -1
    this.taskParamListSelectCurrentRowData = toTaskParamVO()
    this.taskParamStore.queryVo(this.$toParam<TaskParamQO>(this.$toSearch({ ...this.taskParamFormQueryModel }))).then((res: Res<TaskParamVO>) => {
      if (res.succ) {
        this.taskParamListPaginationVisible = false
        this.taskParamListDataSet = [ ...res.data ]
        this.taskParamListDataCount = res.count
        setTimeout(() => { this.taskParamFormQuerySubmitting = false }, 5000)
        setTimeout(() => { this.taskParamListLoading = false }, 500)
      } else {
        this.$message.error(res.msg, 6)
        setTimeout(() => { this.taskParamFormQuerySubmitting = false }, 5000)
        setTimeout(() => { this.taskParamListLoading = false }, 500)
      }
    }).catch(err => {
      setTimeout(() => { this.taskParamFormQuerySubmitting = false }, 5000)
      setTimeout(() => { this.taskParamListLoading = false }, 500)
    })
  }

  taskParamEditDrawerVisible: boolean = false

  taskParamFormSaveSubmitting: boolean = false

  taskParamFormSaveContinue: boolean = false

  taskParamFormModel: TaskParam = toTaskParam()

  taskParamFormRules: object = {
    // paramName: [
    //   { type: 'string', required: true, message: '参数名不能为空！', trigger: ['change', 'blur'] },
    // ],
    // paramValue: [
    //   { type: 'string', required: true, message: '参数值不能为空！', trigger: ['change', 'blur'] },
    // ],
    // weightOrder: [
    //   { type: 'number', required: true, message: '排序权重不能为空！', trigger: ['change', 'blur'] },
    // ],
    // fkid: [
    //   { type: 'string', required: true, message: '外键Id不能为空！', trigger: ['change', 'blur'] },
    // ],
  }

  taskParamFormReset() {
    if (this.$refs.taskParamFormRef) {
      this.$refs.taskParamFormRef.resetFields()
      this.taskParamFormModel = toTaskParam()
    }
  }

  taskParamFormSubmit() {
    this.taskParamFormSaveSubmitting = true
    this.$refs.taskParamFormRef.validate().then(() => {
      if (this.taskParamFormModel.id) {
        this.taskParamStore.update(this.$toParam<TaskParam>(this.taskParamFormModel)).then((res: Res<TaskParam>) => {
          if (res.succ) {
            this.$message.success(res.msg, 3)
            this.taskParamFormReset()
            this.taskParamFormSaveSubmitting = false
            if (!this.taskParamFormSaveContinue) {
              this.taskParamEditDrawerVisible = false
              this.taskParamListGetDataSet()
            }
          } else {
            this.$message.error(res.msg, 6)
            setTimeout(() => { this.taskParamFormSaveSubmitting = false }, 3000)
          }
        }).catch(err => {
          setTimeout(() => { this.taskParamFormSaveSubmitting = false }, 3000)
        })
      } else {
        this.taskParamStore.save(this.$toParam<TaskParam>(this.taskParamFormModel)).then((res: Res<TaskParam>) => {
          if (res.succ) {
            this.$message.success(res.msg, 3)
            this.taskParamFormReset()
            this.taskParamFormSaveSubmitting = false
            if (!this.taskParamFormSaveContinue) {
              this.taskParamEditDrawerVisible = false
              this.taskParamListGetDataSet()
            }
          } else {
            this.$message.error(res.msg, 6)
            setTimeout(() => { this.taskParamFormSaveSubmitting = false }, 3000)
          }
        }).catch(err => {
          setTimeout(() => { this.taskParamFormSaveSubmitting = false }, 3000)
        })
      }
    }).catch(() => {
      setTimeout(() => { this.taskParamFormSaveSubmitting = false }, 3000)
    })
  }

  taskParamFormSave() {
    this.taskParamFormSaveContinue = false
    this.taskParamFormSubmit()
  }

  taskParamFormNextAdd() {
    this.taskParamFormSaveContinue = true
    this.taskParamFormSubmit()
  }

  taskParamAdd() {
    if (this.taskParamFormModel.id) {
      this.taskParamFormReset()
    }
    this.taskParamEditDrawerVisible = true
  }

  taskParamUpdate() {
    this.taskParamStore.pk(this.$toParam<TaskParamQO>({ id: this.taskParamListSelectData[0].id } as TaskParamQO)).then((res: Res<TaskParam>) => {
      if (res.succ) {
        this.taskParamFormReset()
        this.taskParamFormModel = { ...res.data[0] }
        this.taskParamEditDrawerVisible = true
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  taskParamEditDrawerOnClose() {
    if (this.taskParamFormSaveContinue) {
      this.taskParamFormSaveContinue = false
      this.taskParamListGetDataSet()
    }
  }

  taskParamDelete() {
    let param: Array<TaskParam> = []
    this.taskParamListSelectData.forEach((eo: TaskParamVO) => {
      param.push({ id: eo.id } as TaskParam)
    })
    this.taskParamStore.removeBatch(this.$toParam<TaskParam>(param)).then((res: Res<TaskParam>) => {
      if (res.succ) {
        this.$message.success(res.msg, 3)
        this.taskParamListGetDataSet()
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  taskParamDetailDrawerVisible: boolean = false

  taskParamDetailModel: TaskParamVO = toTaskParamVO()

  taskParamDetailInfo() {
    this.taskParamStore.pkVo(this.$toParam<TaskParamQO>({ id: this.taskParamListSelectData[0].id } as TaskParamQO)).then((res: Res<TaskParamVO>) => {
      if (res.succ) {
        this.taskParamDetailModel = { ...res.data[0] }
        this.taskParamDetailDrawerVisible = true
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  taskParamDetailUpdate() {
    this.taskParamStore.pk(this.$toParam<TaskParamQO>({ id: this.taskParamDetailModel.id } as TaskParamQO)).then((res: Res<TaskParam>) => {
      if (res.succ) {
        this.taskParamFormReset()
        this.taskParamFormModel = { ...res.data[0] }
        this.taskParamDetailDrawerVisible = false
        this.taskParamEditDrawerVisible = true
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  taskParamTemplateDownload() {
    this.coreToolStore.getValueByConfKey('defaultDataImportTemplate').then((res: string) => {
      window.open(this.coreToolStore.getFileFullUrl(res), '_blank')
    })
  }

  taskParamDataImportDrawerVisible: boolean = false

  taskParamDataImportFileSelectDrawerVisible: boolean = false

  taskParamDataImportFileModule: string = 'dataImport'

  taskParamDataImportFileUrl: string = ''

  taskParamDataImportSaveSubmitting: boolean = false

  taskParamDataImport() {
    this.taskParamDataImportDrawerVisible = true
  }

  taskParamDataImportFileUploadChange(value) {
    this.taskParamDataImportFileUrl = value
  }

  taskParamDataImportFileUrlSelectFileClick() {
    this.taskParamDataImportFileSelectDrawerVisible = true
  }

  taskParamDataImportFileSelectChange(fileUrl) {
    this.taskParamDataImportFileUrl = fileUrl
    this.taskParamDataImportFileSelectDrawerVisible = false
  }

  taskParamToDataImport() {
    this.taskParamDataImportSaveSubmitting = true
    this.taskParamStore.dataImport(this.$toParam<string>(this.taskParamDataImportFileUrl)).then((res: Res<TaskParam>) => {
      if (res.succ) {
        this.$message.success(res.msg, 3)
        this.$refs.taskParamDataImportFileUploadRef.resetFiles()
        this.taskParamDataImportFileUrl = ''
        this.taskParamDataImportSaveSubmitting = false
        this.taskParamDataImportDrawerVisible = false
        this.taskParamListGetDataSet()
      } else {
        this.$message.error(res.msg, 6)
        setTimeout(() => { this.taskParamDataImportSaveSubmitting = false }, 3000)
      }
    }).catch(err => {
      setTimeout(() => { this.taskParamDataImportSaveSubmitting = false }, 3000)
    })
  }

  taskParamDataExportDrawerVisible: boolean = false

  taskParamOptionalDataExportFieldList: Array<DataExportFieldAO> = [
    {
      fieldName: 'paramName',
      fieldComment: '参数名',
    },
    {
      fieldName: 'paramValue',
      fieldComment: '参数值',
    },
    {
      fieldName: 'weightOrder',
      fieldComment: '排序权重',
    },
    {
      fieldName: 'fkid',
      fieldComment: '外键Id',
    },
  ]

  taskParamSelectedDataExportFieldList: Array<DataExportFieldAO> = []

  taskParamDataExport() {
    this.taskParamDataExportDrawerVisible = true
  }

  taskParamToDataExport(allData: boolean) {
    this.taskParamStore.dataExport(this.$toParam<DataExportAO<TaskParamQO>>(toDataExportAO(this.taskParamSelectedDataExportFieldList, allData ? { weightOrderAsc: 'y' } as TaskParamQO : this.$toSearch({ ...this.taskParamFormQueryModel }), '任务参数信息数据导出.xlsx'))).then((res: Res<string>) => {
      if (res.succ) {
        window.open(this.coreToolStore.getFileFullUrl(res.data[0]), '_blank')
      } else {
        this.$message.error(res.msg, 6)
      }
    })
  }

  mounted() {
    this.taskParamListGetDataSet()
  }

}
</script>

<style scoped lang="less">

</style>
